package com.hf.bill

import com.hf.order.OrderPeriod
import com.hf.security.OrderUser

class UserBillPeriodHistoryService {

	UserBillPeriodHistory getUserBillPeriodHistory(OrderPeriod orderPeriod, OrderUser user, int count) {
		UserBillPeriodHistory userBillPeriodHistory = UserBillPeriodHistory.findByUserAndOrderPeriod(user, orderPeriod)
		if(!userBillPeriodHistory) {
			userBillPeriodHistory = new UserBillPeriodHistory(user : user, orderPeriod : orderPeriod, orderCount : count, lastOweMoney : user.oweMoney)
		} else {
			userBillPeriodHistory.orderCount = count
		}
		userBillPeriodHistory.save()

		return userBillPeriodHistory
	}
}
